//
//  FlipsideViewController.h
//  RunSketch
//
//  Created by Brian on 10/1/09.
//  Copyright Tellart 2009. All rights reserved.
//

#import "SketchUpdateController.h"
#import "BonjourBrowser.h"

@protocol FlipsideViewControllerDelegate;


@interface FlipsideViewController : UIViewController
    <SketchUpdateControllerDelegate,
    BonjourBrowserDelegate,
    NADAMobileIOHelperDelegate,
    UITextFieldDelegate>
{
	id <FlipsideViewControllerDelegate> delegate;

    SketchUpdateController *sketchUpdater;
	BonjourBrowser *browser;
    
    BOOL reloadSketchOnDone;

    UITextField *sketchServerTextField;
	UIButton *updateSketchButton;
    UILabel *updatingLabel;
    UIActivityIndicatorView *updateActivity;
    UIProgressView *updateProgress;
	UIButton *cancelUpdateButton;
	UISwitch *flowControlSwitch;
	UISwitch *iopackBoostSwitch;
    UISwitch *localIOPackEnabledSwitch;
    
    UILabel *networkConnecting;
    UIImageView *networkError;
    UIImageView *networkConnection;
    UIImageView *localSerialError;
    UIImageView *localSerialConnection;
    
    /** monitor elements **/
    UIScrollView *monitorScroller;
    UIView *monitorView;
    UILabel *sketchOnAudioAmplitude_v;
    UILabel *sketchOnAudioProfile_l;
    UILabel *sketchOnAudioProfile_m;
    UILabel *sketchOnAudioProfile_h;
    
    UILabel *sketchOnLocation_lat;
    UILabel *sketchOnLocation_lon;
    UILabel *sketchOnLocation_alt;
    UILabel *sketchOnAccelerate_x;
    UILabel *sketchOnAccelerate_y;
    UILabel *sketchOnAccelerate_z;
    UILabel *sketchOnHeading_heading;
    UILabel *sketchOnProximity_isClose;
    UILabel *sketchOnOrientation_orientation;
    UILabel *sketchOnBattery_level;
    
    UILabel *sketchOnIOPackInput_remote;
    UILabel *sketchOnIOPackInput_local;
}

@property (nonatomic, assign) id <FlipsideViewControllerDelegate> delegate;
@property (nonatomic, retain) SketchUpdateController *sketchUpdater;
@property (nonatomic, retain) BonjourBrowser *browser;

@property (nonatomic, retain) IBOutlet UITextField *sketchServerTextField;
@property (nonatomic, retain) IBOutlet UIButton *updateSketchButton;
@property (nonatomic, retain) IBOutlet UILabel *updatingLabel;
@property (nonatomic, retain) IBOutlet UIActivityIndicatorView *updateActivity;
@property (nonatomic, retain) IBOutlet UIProgressView *updateProgress;
@property (nonatomic, retain) IBOutlet UIButton *cancelUpdateButton;
@property (nonatomic, retain) IBOutlet UISwitch *flowControlSwitch;
@property (nonatomic, retain) IBOutlet UISwitch *iopackBoostSwitch;
@property (nonatomic, retain) IBOutlet UISwitch *localIOPackEnabledSwitch;

@property (nonatomic, retain) IBOutlet UILabel *networkConnecting;
@property (nonatomic, retain) IBOutlet UIImageView *networkError;
@property (nonatomic, retain) IBOutlet UIImageView *networkConnection;
@property (nonatomic, retain) IBOutlet UIImageView *localSerialError;
@property (nonatomic, retain) IBOutlet UIImageView *localSerialConnection;

/** monitor elements **/
@property (nonatomic, retain) IBOutlet UIScrollView *monitorScroller;
@property (nonatomic, retain) IBOutlet UIView *monitorView;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnAudioAmplitude_v;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnAudioProfile_l;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnAudioProfile_m;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnAudioProfile_h;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnLocation_lat;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnLocation_lon;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnLocation_alt;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnAccelerate_x;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnAccelerate_y;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnAccelerate_z;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnHeading_heading;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnProximity_isClose;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnOrientation_orientation;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnBattery_level;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnIOPackInput_remote;
@property (nonatomic, retain) IBOutlet UILabel *sketchOnIOPackInput_local;

- (IBAction)done;
- (IBAction)updateSketchFromServer;
- (IBAction)cancelSketchUpdate;
- (IBAction)showBonjourBrowser;
- (IBAction)changedSketchServerAddress;
- (IBAction)changedLocalIOPackEnabled;

- (void) updateIndicators;
- (void)autoUpdateSketchFromServer;
- (void)testSketchServer;

-(void) didStartSketchServerTest;
-(void) didFinishTest: (SketchUpdateController *)c result:(BOOL)passed;
-(void) didStartManualSketchUpdate;
-(void) didStartAutoSketchUpdate;
-(void) didChooseSketch: (SketchUpdateController *)c;
-(void) didFailWithConnectionError: (SketchUpdateController *)c;
-(void) didFailWithCommunicationError: (SketchUpdateController *)c message:(NSString *)msg;
-(void) didLoadCatalog: (SketchUpdateController *)c;
-(void) didFailWithCatalogParserError: (SketchUpdateController *)c error:(NSError *)err;
-(void) madeProgress: (SketchUpdateController *)c loaded:(int)bytesLoaded total:(int)bytesTotal;
-(void) didSucceed: (SketchUpdateController *)c;
-(void) didStop: (SketchUpdateController *)c;

-(void) updateIOPackMonitor:(NSString *)adddress inputs:(NSString *)inputsTrace outputs:(NSString *)outputsTrace; 

- (BOOL)textFieldShouldReturn:(UITextField *)textField;

@end


@protocol FlipsideViewControllerDelegate

- (NSString *) flipsideViewControllerGetRemoteIOPackHostName;
- (BOOL) flipsideViewControllerWasAutoUpdateRequested;
- (BOOL) flipsideViewControllerGetEnableLocalIOPack;
- (BOOL) flipsideViewControllerIsRemoteIOPackConnected;
- (BOOL) flipsideViewControllerIsRemoteIOPackError;
- (BOOL) flipsideViewControllerIsLocalIOPackConnected;
- (BOOL) flipsideViewControllerIsLocalIOPackError;
- (void)flipsideViewControllerDidFinish:(FlipsideViewController *)controller reloadSketch:(BOOL)reload;
- (void)flipsideViewControllerDidChangeRemoteIOPackHostName:(FlipsideViewController *)controller to:(NSString*)hostName;
- (void)flipsideViewControllerDidChangeFlowControl:(FlipsideViewController *)controller to:(BOOL)state;
- (void)flipsideViewControllerDidChangeIOPackBoost:(FlipsideViewController *)controller to:(BOOL)state;
- (void)flipsideViewControllerDidChangeLocalIOPackEnabled:(FlipsideViewController *)controller to:(BOOL)state;
@end

